#include <cstdio>
#include <algorithm>

using namespace std;

struct Stu
{
    int h, l, t;
};

bool operator < ( Stu a, Stu b )
{
    if ( a.t < b.t )
        return true;
    if ( a.t > b.t )
        return false;
    if ( a.l < b.l )
        return true;
    return false;
}

int f[ 100000 ], n, total;
Stu stu[ 31 ];

void init( )
{
    int i;
    total = 0;
    for ( i = 0; i < n; i++ )
    {
        scanf("%d%d%d", &stu[ i ].h, &stu[ i ].l, &stu[ i ].t);
        if ( total < stu[ i ].t )
            total = stu[ i ].t;
    }
    sort( stu, stu + n );
    for ( i = 0; i <= total; i++ )
        f[ i ] = 0;
}

void work( )
{
    int i, j, k;
    for ( i = 0; i < n; i++ )
        for ( j = stu[ i ].t; j >= stu[ i ].l; j-- )
            if ( f[ j ] < f[ j - stu[ i ].l ] + stu[ i ].h )
            {
                f[ j ] = f[ j - stu[ i ].l ] + stu[ i ].h;
                for ( k = j + 1; k <= total; k++ )
                    if ( f[ j ] > f[ k ] )
                        f[ k ] = f[ j ];
                    else
                        break;
            }
    printf("%d\n", f[ total ]);
}

int main( )
{
    while ( scanf("%d", &n) && n >= 0 )
    {
        init( );
        work( );
    }
    return 0;
}
